const { defineConfig } = require('@vue/cli-service')
const { name, subPort } = require('./package.json')
const webpack = require('webpack')
const path = require('path')
const testObj = {
  name: '123',
  age: '232',
  sd: 'asdsadasdasdas'
}

const publicPath = process.env.NODE_ENV === 'production' ? `/${name}` : '/'
module.exports = defineConfig({
  publicPath,
  outputDir: `dist/${name}`,
  productionSourceMap: false,
  transpileDependencies: true,
  chainWebpack: config => {
    config.plugin('define').tap(definitions => {
      Object.assign(definitions[0], {
        __VUE_OPTIONS_API__: true,
        __VUE_PROD_DEVTOOLS__: false,
        __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false
      })
      return definitions
    })
  },
  configureWebpack: {
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src')
      }
    },
    output: {
      libraryTarget: 'umd',
      library: `${name}-[name]`,
      chunkLoadingGlobal: `webpackJsonp_${name}`
    },
    plugins: [
      new webpack.DefinePlugin({
        MY_CONFIG: JSON.stringify(testObj)
      })
    ]
  },
  devServer: {
    port: subPort,
    https: false,
    open: true,
    historyApiFallback: true,
    allowedHosts: 'all',
    client: {
      overlay: false
    },
    headers: {
      'Access-Control-Allow-Origin': '*'
    },
    proxy: {
      '/bytserver': {
        target: 'http://192.168.0.161:9999',
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/bytserver': ''
        }
      },
      '/minio': {
        target: 'http://192.168.0.161:9000',
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/minio': ''
        }
      }
    }
  }
})
